package sandbox.vaadin;

import java.text.SimpleDateFormat;

import org.apache.log4j.Logger;

import com.vaadin.server.Sizeable.Unit;
import com.vaadin.ui.Component;

public class Util
{
	private final static Logger LOGGER = Logger.getLogger(Util.class);

	public static final SimpleDateFormat SDF_TIMESTAMP =
			new SimpleDateFormat("YYYY.MM.dd HH:mm:ss.SSS");
	
	public static class Size
	{
		public float value;
		public Unit unit;

		public Size(float value, Unit unit)
		{
			this.value = value;
			this.unit = unit;
		}
		
		public static Size FULL = new Size(100, Unit.PERCENTAGE);
	}

	public static void setSize(Component component, Size size)
	{
		setSize(component, size, size);
	}

	public static void setSize(Component component, Size width, Size height)
  {
		StringBuffer sb =
				new StringBuffer(
						"\n" + component.getClass().getName() + " " +
						"width  initial:  " + component.getWidth()  + " " + component.getWidthUnits() + " " +
						"heigth initial:  " + component.getHeight() + " " + component.getHeightUnits());

		component.setWidth(width.value, width.unit);
		component.setHeight(height.value, height.unit);

		sb.append(
						"\n" + component.getClass().getName() + " " +
						"width  adjusted: " + component.getWidth()  + " " + component.getWidthUnits() + " " +
						"heigth adjusted: " + component.getHeight() + " " + component.getHeightUnits());
		
		LOGGER.debug(sb);
  }
}